//
//  Root1ViewController.m
//  UI_豆瓣影院
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "Root1ViewController.h"
#import "RootViewController.h"
#import "AAALHXDateHandle.h"

@interface Root1ViewController ()
@end

@implementation Root1ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
   
    UIScrollView *scro = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];
    scro.contentSize = CGSizeMake(0, _heightl + 350);
    scro.bounces = YES;
    scro.showsVerticalScrollIndicator = NO;
    [self.view addSubview:scro];
    [scro release];
   
    
    self.view.backgroundColor = [UIColor whiteColor];
   
    self.navigationItem.title = self.model.title;
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-jiantou.png"] style:UIBarButtonItemStylePlain target:self action:@selector(itemAction)];
   
    
    self.navigationItem.leftBarButtonItem = item;
    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-share.png"] style:UIBarButtonItemStylePlain target:self action:@selector(itemAction2)];
    self.navigationItem.rightBarButtonItem = item1;
    
    
    
    UILabel *lable2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 50)];
    lable2.text = self.model.title;
    lable2.font = [UIFont boldSystemFontOfSize:20];
    //    lable2.backgroundColor = [UIColor yellowColor];
    [scro addSubview:lable2];
   
    
    
    UILabel *lable3 = [[UILabel alloc] initWithFrame:CGRectMake(155, 70, 200, 30)];
    NSString *str1 = self.model.begin_time;
    NSString *str2 = [str1 substringWithRange:NSMakeRange(5, 11)];
    NSString *str3 = self.model.end_time;
    NSString *str4 = [str3 substringWithRange:NSMakeRange(5, 11)];
    NSString *str5 = [NSString stringWithFormat:@"%@ -- %@", str2, str4];
    lable3.text = str5;
    //    lable3.backgroundColor = [UIColor yellowColor];
    [scro addSubview:lable3];
    
    
    
    UILabel *lable4 = [[UILabel alloc] initWithFrame:CGRectMake(155, 110, 200, 30)];
    lable4.font = [UIFont systemFontOfSize:15];
    lable4.text = [NSString stringWithFormat:@"%@", self.model.ownerName];
    //    lable4.backgroundColor = [UIColor yellowColor];
    [scro addSubview:lable4];
   
    
    
    UILabel *lable5 = [[UILabel alloc] initWithFrame:CGRectMake(155, 150, 200, 30)];
    lable5.text = [NSString stringWithFormat:@"%@%@", @"类型: ", self.model.category_name];
    //    lable5.backgroundColor = [UIColor yellowColor];
    [scro addSubview:lable5];
   
    
    
    UILabel *lable6 = [[UILabel alloc] initWithFrame:CGRectMake(155, 190, 200, 30)];
    lable6.font = [UIFont systemFontOfSize:15];
    lable6.text = [NSString stringWithFormat:@"%@", self.model.address];
    //    lable6.backgroundColor = [UIColor yellowColor];
    [scro addSubview:lable6];
   
    
    
    
    UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(10, 70, 140, 220)];
    imageview.backgroundColor = [UIColor cyanColor];
    [imageview sd_setImageWithURL:[NSURL URLWithString:self.model.image]];
    [scro addSubview:imageview];
    
    
    
    UILabel *lable1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 330, 375, 20)];
    lable1.text = @"活动介绍";
    lable1.font = [UIFont boldSystemFontOfSize:20];
    
    [scro addSubview:lable1];
    
    
 // 自适应高度
    UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 360, 375, _heightl)];
    lable.numberOfLines = 10000;
    lable.text = self.model.content;
    [scro addSubview:lable];
    [lable release];

    
    
        
}

// 箭头方法
- (void)itemAction {
    
    [self.navigationController popToRootViewControllerAnimated:YES];
    
}

// 收藏方法
- (void)itemAction2 {
    NSMutableArray *arr = [[AAALHXDateHandle sharedDateBaseHandle]selectTable2];
    
    myModel *model = [myModel model];
    model = [arr lastObject];
    NSInteger i = model.type;
    if (i == 0) {
        
        NSArray *array = [[AAALHXDateHandle sharedDateBaseHandle] selectTable];
        if ([array containsObject:_model.title]) {
            UIAlertController *hadCollectAlert = [UIAlertController alertControllerWithTitle:@"收藏提示" message:@"该活动已经被收藏过" preferredStyle:(UIAlertControllerStyleAlert)];
            [self presentViewController:hadCollectAlert animated:YES completion:nil];
            [self performSelector:@selector(time) withObject:hadCollectAlert afterDelay:1];
              model.type = 1;
        } else {
            if (![array containsObject:_model.title]) {
                [[AAALHXDateHandle sharedDateBaseHandle] insertModel:_model];
                UIAlertController *collectAlert = [UIAlertController alertControllerWithTitle:@"收藏提示" message:@"收藏成功" preferredStyle:(UIAlertControllerStyleAlert)];
                [self presentViewController:collectAlert animated:YES completion:nil];
                [self performSelector:@selector(time1) withObject:collectAlert afterDelay:1];
                
            }
            
        }
    } else {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请先登录" preferredStyle:(UIAlertControllerStyleAlert)];
        [self presentViewController:alert animated:YES completion:nil];
        
        [self dismissViewControllerAnimated:alert completion:nil];
        
        
        
        
    }
    
 
}

// alert 方法
- (void)time {
    [self dismissViewControllerAnimated:YES completion:nil];

}
- (void)time1 {
     [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
